<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *售后列表
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
$tabs=array(
	array('op'=>'list','title'=>'用户反馈'),
);
$worker=pdo_get('jy_yxw_worker',array('id'=>$_SESSION['workerid'],'uniacid'=>$_SESSION['uniacid']));
$storeidlist=str_array($worker['storeidlist']);
if(!$storeidlist){
	$storeidlist=-1;
}
//售后列表
if($_RQ['op']=='list' || $_RQ['op']=='fromclass'){
	
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$return['params']=array();
	$params=array('uniacid'=>$_SESSION['uniacid'],'storeid'=>$storeidlist);
	if($_RQ['status']!='all'){
		$params['status']=intval($_RQ['status']);
	}
	$return['params']['status']=$_RQ['status'];
	if($_RQ['storeid']){
		$params['storeid']=intval($_RQ['storeid']);
		$return['params']['storeid']=$_RQ['storeid'];
	}
	if($_RQ['id'] && $_RQ['op']=='fromclass'){
		$params['classid']=intval($_RQ['id']);
		$return['params']['classid']=$_RQ['id'];
		$this->session('classid',$params['classid']);
	}
	if($_RQ['op']=='fromclass'){
		$params['classid']=$this->session('classid');
		$return['params']['classid']=$this->session('classid');
	}
	if(!empty($_RQ['title'])){
		$params['title like']='%'.$_RQ['title'].'%';
		$return['params']['title']=$_RQ['title'];
	}
	if(!empty($_RQ['mobile'])){
		$params['mobile']=$_RQ['mobile'];
		$return['params']['mobile']=$_RQ['mobile'];
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = $_RQ['psize']?:30;
	if($_RQ['psize']){
		$return['params']['psize']=$_RQ['psize'];
	}
	$list=pdo_getslice('jy_yxw_yonghu',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){
			$item['member']=$this->model('yonghu')->member_show($item['id']);
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	//页面显示设置
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'export'=>'export',
		'list'=>array('data'=>'list','del_message'=>'确认删除该售后吗？','total'=>$total,'psize'=>$psize,'del_one'=>false,'delall'=>false,'edit'=>false,'html_to'=>'list_html','list'=>array(
			array('title'=>'名称/电话','type'=>'img_string',
			'data'=>array(
				array('title'=>'名称：','name'=>'title'),
				array('title'=>'电话：','name'=>'mobile')
				)
			),
			array('name'=>'storeid','title'=>'所属门店','type'=>'select2','options'=>'stores'),
			array('name'=>'sn','title'=>'编号','type'=>'string'),
			array('name'=>'classid','title'=>'售后群','type'=>'select2','options'=>'class'),
			array('name'=>'kaoqing','title'=>'考勤次数','type'=>'string'),
			array('name'=>'weijinum','title'=>'违纪次数','type'=>'string'),
			array('name'=>'status','title'=>'状态','type'=>'radio2','options'=>'status'),
			array('name'=>'createtime','title'=>'日期','type'=>'time'),
		),'action'=>array(
			array('type'=>'modal','op'=>'setstore','title'=>'修改门店'),
			array('type'=>'modal','op'=>'look','title'=>'售后信息'),
		),'batch'=>$batch),
		'search'=>array(
			array('type'=>'string','width'=>'15','title'=>'手机号','name'=>'mobile','help'=>''),
			array('type'=>'string','width'=>'15','title'=>'售后名称','name'=>'title','help'=>''),
			array('name'=>'status','width'=>'15','title'=>'状态','type'=>'radio','options'=>'status'),
			array('name'=>'storeid','width'=>'15','title'=>'所属门店','type'=>'select','options'=>'stores'),
		),
	);
	$return['stores']=$this->getall('store',array('uniacid'=>$_SESSION['uniacid']),array('id','title'),'id');
	$return['workers']=$this->getall('worker',array('uniacid'=>$_SESSION['uniacid']),array('id','title'),'id');	
	$return['status']=$this->yonghu_status;
	$return['jibie_type']=$this->member_jibie_type;
	$return['from_type']=$this->member_from_type;
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='look'){
	$return=array();
	$id=intval($_RQ['id']);
	if($id){
		$yonghu=pdo_get('jy_yxw_yonghu',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		$item=pdo_get('jy_yxw_member',array('id'=>$yonghu['memberid'],'uniacid'=>$_SESSION['uniacid']));
		$item=array_merge($item,$yonghu);
	}else{
		//exi('请选择客户！','error');
	}
	$return['item']=$item;
	$htmls=array(
		'type'=>'look',
		'look'=>array(
			array('type'=>'string','title'=>'客户名称','name'=>'title'),
			array('type'=>'string','title'=>'手机号','name'=>'mobile'),
			array('type'=>'string','title'=>'备用手机号','name'=>'mobile2'),
			array('name'=>'from_type','title'=>'渠道','type'=>'radio','options'=>'from_type'),
			array('name'=>'from1_type','title'=>'线下来源渠道','type'=>'radio','options'=>'member_from1_type','show'=>array('from_type'=>1)),
			array('name'=>'from2_type','title'=>'网络来源渠道','type'=>'radio','options'=>'member_from2_type','show'=>array('from_type'=>2)),
			array('type'=>'string','title'=>'微信号','name'=>'wechat'),
			array('type'=>'string','title'=>'邮箱','name'=>'email'),
			array('type'=>'string','title'=>'QQ','name'=>'qq'),
			array('type'=>'string','title'=>'专业','name'=>'zhuanye'),
			array('type'=>'string','title'=>'完结学校','name'=>'school'),
			array('type'=>'radio','title'=>'学历','name'=>'xueli','options'=>'xueli_type'),
			array('type'=>'string','title'=>'应聘岗位','name'=>'gangwei'),
			array('type'=>'string','title'=>'工作经验','name'=>'workdesc'),
			array('type'=>'radio','title'=>'性别','name'=>'sex','options'=>'sex'),
			array('type'=>'string','title'=>'生日','name'=>'birth','help'=>''),
			array('type'=>'pcd','title'=>'户籍','name'=>'pcd','help'=>''),
			array('type'=>'string','title'=>'详细地址','name'=>'address','help'=>''),
		)
	);
	$return['sex']=$this->sex;
	$return['xueli_type']=$this->xueli_type;
	$return['from_type']=$this->member_from_type;
	$return['member_from1_type']=$this->member_from1_type;
	$return['member_from2_type']=$this->member_from2_type;
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='export'){
	//售后列表
	$return['params']=array();
	$params=array('uniacid'=>$_SESSION['uniacid'],'storeid'=>$storeidlist);
	if($_RQ['classid']){
		$params['classid']=intval($_RQ['classid']);
		$return['params']['classid']=$_RQ['classid'];
	}
	$return['params']['status']=$_RQ['status'];
	if(!empty($_RQ['title'])){
		$params['title like']='%'.$_RQ['title'].'%';
		$return['params']['title']=$_RQ['title'];
	}
	if(!empty($_RQ['mobile'])){
		$params['mobile']=$_RQ['mobile'];
		$return['params']['mobile']=$_RQ['mobile'];
	}
	$list=pdo_getall('jy_yxw_yonghu',$params,$fields);
	if($list){
		foreach($list as &$item){
			$item['status']=$this->yonghu_status[$item['status']];
			$item['createtime']=date('Y/m/d H:i:s',$item['createtime']);
		}
	}
	$header=array(
		'id'=>'售后ID',
		'title'=>'售后姓名',
		'mobile'=>'手机号',
		'mobile2'=>'手机号',
		'status'=>'售后状态',
		'createtime'=>'注册时间',
	);
	model('core/tools')->export2excel($header,$list,'售后数据');
}

if($_RQ['op']=='setstore'){
	if($_RQ['postdata']){
		$post=get_postdata();
		$ids=$post['ids'];
		foreach($ids as $id){
			$id=intval($id);
			if($id){
				pdo_update('jy_yxw_yonghu',array('storeid'=>intval($post['storeid'])),array('uniacid'=>$_SESSION['uniacid'],'id'=>$id));
			}
		}
		exi('操作成功！','','//list/');
	}
	$ids=trim($_RQ['ids'],';');
	if($ids){
		$ids=explode(';',$ids);
	}else{
		$ids=array();
	}
	if($_RQ['id']){
		$ids[]=$_RQ['id'];
		$item=pdo_get('jy_yxw_yonghu',array('uniacid'=>$_SESSION['uniacid'],'id'=>$_RQ['id']),array('storeid','id'));
	}
	if(count($ids)==0){
		exi('请先选择售后','error');
	}
	$item['ids']=$ids;
	$return['item']=$item;	
	$htmls=array(
		'type'=>'edit',
		'desc'=>'绑定门店',
	);
	$htmls['edit']=array(
		array('type'=>'select','title'=>'绑定门店','name'=>'storeid','options'=>'stores'),
	);
	$return['htmls']=$htmls;
	$return['stores']=$this->getall('store',array('uniacid'=>$_SESSION['uniacid']),array('id','title'));	
	exi($return);
}
if($_RQ['op']=='del'){
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
	}else{
		$del=array();
	}
	if($_RQ['id']){
		$del[]=$_RQ['id'];
	}
	foreach($del as $id){
		$id=intval($id);
		if($id){
			pdo_delete('jy_yxw_yonghu',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		}
	}
	exi('删除成功！');
}